<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>Ajax</title>
</head>
<body>
<script>
    var request = new XMLHttpRequest();
    request.open('get', 'http://localhost:8089/demo.html', false);
    request.send(null);

    var status = request.status;
    if (status == 200) {
        alert('The text file was found!');
    } else if (status == 404) {
        alert('The text file could not be found!');
    } else {
        alert('The server returned a status code of ' + status);
    }
</script>
<script>
    var request = new XMLHttpRequest();
    request.open('get', 'http://localhost:8089/demo.html', false);
    request.send(null);

    var status = request.status;
    if (status == 200) {
        alert('The text file was found!');
    } else {
        alert('The server returned a status code of ' + status);
    }
</script>
<script>
    var request = new XMLHttpRequest();
    request.open('get', 'http://localhost:8089/demo.html');
    request.onreadystatechange = reqReadyStateChange;
    request.send(null);

    function reqReadyStateChange() {
        if (request.readyState == 4) {
            var status = request.status;
            if (status == 200) {
                alert(request.responseText);
            } else {
                alert('The server returned a status code of ' + status);
            }
        }
    }
</script>
<script>
    function HttpRequest(url, callback) {
        this.request = new XMLHttpRequest();
        //    more code here
    }

</script>
<script>
    function HttpRequest(url, callback) {
        this.request = new XMLHttpRequest();
        this.request.open('GET', url);
        this.request.onreadystatechange = reqReadyStateChange;

        function reqReadyStateChange() {
            //    more code here
        }
    }
</script>
<script>
    function HttpRequest(url, callback) {
        this.request = new XMLHttpRequest();
        this.request.open('GET', url);
        this.request.onreadystatechange = reqReadyStateChange;

        var that = this;

        function reqReadyStateChange() {
            if (that.request.readyState == 4) {
                if (that.request.status == 200) {
                    callback(that.request.responseText);
                } else {
                    alert('An error occurred trying to contact the server.');
                }
            }
        }
    }
</script>
<script>
    HttpRequest.prototype.send = function () {
        this.request.send(null);
    }
</script>
<script>
    function HttpRequest(url, callback) {
        this.request = new XMLHttpRequest();
        this.request.open('GET', url);
        this.request.onreadystatechange = reqReadyStateChange;

        var that = this;

        function reqReadyStateChange() {
            if (that.request.readyState == 4) {
                if (that.request.status == 200) {
                    callback(that.request.responseText);
                } else {
                    alert('An error occurred trying to contact the server.');
                }
            }
        }
    }

    HttpRequest.prototype.send = function () {
        this.request.send(null);
    }
</script>
<script>
    function handleData(text) {
        alert(text);
    }

    var request = new HttpRequest('http://localhost:8089/demo.html', handleData);
    request.send();
</script>
<script>
    top.handleResponse('{"available":false, "value":"jmcpeak"');
</script>
<script>
    function requestComplete(text) {
        //    do something with the data here
        document.getElementById('loading').sytle.display = 'none';
    }

    var request = new HttpRequest('http://localhost:8089/demo.html', requestComplete);
    //    show that're loading
    document.getElementById('loading').style.display = 'block';
    request.send();
</script>
<a href="http://www.wrox.com" title="Wrox Publishing">Wrox Publishing</a>
</body>
</html>